﻿using System;
using System.Collections.Generic;
using System.Text;

namespace VOAEnglishDownloaderConsole
{

    public class Class1
    {
        private SharpDownloadSDK.HttpWebRequestDownloader downloader = new SharpDownloadSDK.HttpWebRequestDownloader();
        private VOAEnglishDownload.VOASpecialEnglish voaUrls = new VOAEnglishDownload.VOASpecialEnglish();

        public Class1()
        {
            downloader.DownloadFileCompletedEvent += new SharpDownloadSDK.DownloadFileCompleted(DownLoadFileCompletedEventHandler);
            voaUrls.SaveDirectory = @"E:\VOA\";
            voaUrls.AnalyseFileCompletedEvent1 += new VOAEnglishDownload.VOASpecialEnglish.AnalyseFileCompletedEvent(AnalyseFileCompletedEventHandler);
        }

        public void Download()
        {
            for (int i = 2001; i <= 2007; ++i)
            {
                voaUrls.VOAYear = i;
                voaUrls.GetUrls();
            }
        }
        public static void Main()
        {
            Class1 a = new Class1();
            a.Download();            
        }

        private void AnalyseFileCompletedEventHandler(String url, String fullPath)
        {            
            
            downloader.UrlAndSavePaths.Add(url, fullPath);
            downloader.DownloadFileAsync(url, fullPath);
        }

        private void DownLoadFileCompletedEventHandler(Object sender, SharpDownloadSDK.DownloadFileCompletedEventArgs e)
        {
            String currentFileResult = String.Empty;
            if (e.IsSuccessful)
                currentFileResult = "下载成功：" + e.SavePath;
            else
                currentFileResult = "下载失败：" + e.SavePath;

            Console.WriteLine(currentFileResult);
        }
    }
}
